import re,string
def main():
    str_raw = input("请输入明文")
    m = encode(str_raw,3)
    print(m)
def letter(zifuchuan):
    back = re.sub("[^a-z^A-Z]", "", zifuchuan) 
    return back
def reverse(s):
    str0=""
    l = len(s)-1
    while l>-1:
        str0+=s[l]
        l-=1
    str1 = letter(str0)
    return (str1)
def encode(str,k):
    str1 = reverse(str)
    lower = string.ascii_lowercase #小写字母
    upper = string.ascii_uppercase #大写字母
    before = string.ascii_letters #无偏移的字母顺序 小写+大写
    after = lower[k:] + lower[:k] + upper[k:] + upper[:k]#偏移后的字母顺序 还是小写+大写
    #分别把小写字母和大写字母偏移后再加到一起 
    table = ''.maketrans(before, after)  #创建映射表
    return str1.translate(table) #对s进行偏移 即加密
main()
